/**!
 * cnpmjs.org - worker.js
 *
 * Copyright(c) cnpmjs.org and other contributors.
 * MIT Licensed
 *
 * Authors:
 *  dead_horse <dead_horse@qq.com>
 *  fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
 */

'use strict';

/**
 * Module dependencies.
 */

var graceful = require('graceful');
var logger = require('./common/logger');
var C = require('./config');
var api = require('./servers/apiHTTP');
//var web = require('./servers/webHTTP');
//var manapi = require('./servers/manHTTP');

api.listen(C.apiPort);  //, C.bindingApiHost
//web.listen(C.webPort, C.bindingWebHost);
//manapi.listen(C.manapiPort, C.bindingManApiHost);

console.log('[%s] [worker:%d] Server started, API server listen at %d, cluster: %s',
    new Date(), process.pid,
    C.apiPort,  //C.bindingApiHost,
//  C.bindingWebHost, C.webPort,
//  C.bindingManApiHost, C.manapiPort,
    C.enableCluster);

graceful({
    server: [api],
    error: function (err, throwErrorCount) {
        if (err.message) {
            err.message += ' (uncaughtException throw ' + throwErrorCount + ' times on pid:' + process.pid + ')';
        }
        console.error(err.stack);
        logger.error(err);
    }
});
